<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="68px"
      class="query-form"
      size="small"
    >
      <el-form-item label="设备名称" prop="equName">
        <el-input
          v-model="queryParams.equName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备位置" prop="locationId">
        <el-select v-model="queryParams.locationId" placeholder="请选择上/下行" style="width: 100%;" clearable="">
          <el-option
            v-for="tunnel in tunnelAll"
            :key="tunnel.id"
            :label="tunnel.tunnelName"
            :value="tunnel.id"
          >
            <span style="float: left">{{ tunnel.tunnelName }}（{{ tunnel.direction }}）</span>
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备类型" prop="equType">
        <el-select v-model="queryParams.equType" placeholder="请选择类型" clearable size="small">
          <el-option v-for="dict in equTypes" :label="dict.dictLabel" :value="dict.dictValue" :key="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="正常" :value="0" />
          <el-option label="异常" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fj:equ:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fj:equ:edit']"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fj:equ:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fj:equ:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row> -->
    <div class="content-container" style="padding: 0 ;">
      <div class="flex-1" style="position: relative;overflow: hidden;">
        <div style="position: absolute;left: 0;top: 0;bottom: 0;right: 0;display: flex;flex-direction: column;overflow: hidden;">
          <el-table v-loading="loading" :data="equList">
            <el-table-column label="设备名称" align="center" prop="equName" />
            <el-table-column label="安装位置" align="center" prop="locationName" />
            <el-table-column label="ip地址" align="center" prop="ip" />
            <el-table-column label="设备类型" align="center" prop="equType" :formatter="equTypeFormat" />
            <el-table-column label="安装日期" align="center" prop="installDate" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.installDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <span v-if="scope.row.status == 0" class="text-navy">正常</span>
                <span v-if="scope.row.status == 1" class="text-danger">异常</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listAll } from '@/api/system/tunnel'
import { listEqu, getEqu, delEqu, addEqu, updateEqu } from '@/api/fjgs/tunnelMonitor.js'
// import { listEqu, getEqu, delEqu, addEqu, updateEqu } from "@/api/fj/equ";

export default {
  name: 'Equ',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      // 设备定义表格数据
      equList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equName: null,
        locationName: null,
        produceCompany: null,
        supplier: null,
        brand: null,
        price: null,
        produceDate: null,
        warranty: null,
        ip: null,
        lightType: null,
        equType: null,
        installDate: null,
        locationId: null,
        status: null
      },
      listAll: [],
      equTypes: [],
      tunnelAll: []
    }
  },
  created() {
    this.getList()
    listAll().then(res => {
      this.tunnelAll = res.data
    })
    this.getDicts('conf_equ_type').then(response => {
      this.equTypes = response.data
    })
  },
  methods: {
    equTypeFormat(row) {
      return this.selectDictLabel(this.equTypes, row.equType)
    },
    /** 查询设备定义列表 */
    getList() {
      this.loading = true
      listEqu(this.queryParams).then(response => {
        this.equList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
